/*
 * @Description:
 * @Author: zheng yiliang
 * @Date: 2021-03-27 23:04:55
 * @LastEditTime: 2021-03-28 12:00:04
 * @LastEditors: zheng yiliang
 */

import JSEncrypt from 'jsencrypt'
import { getPublicKey } from '@/api'

// 加密
export async function encryptedData (val) {
  const { _RejCode, data } = await getPublicKey()
  if (_RejCode !== '00000000') return
  const publicKey = data.PUBLIC_KEY
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt()
  // 设置公钥
  encryptor.setPublicKey(publicKey)
  // 加密数据
  return encryptor.encrypt(val)
}
// // 解密
// export function decryptedData (privateKey, data) {
//   // 新建JSEncrypt对象
//   const encryptor = new JSEncrypt()
//   // 设置公钥
//   encryptor.setPrivateKey(privateKey)
//   // 加密数据
//   return encryptor.decrypt(data)
// }
